package com.app.utils.jst.Data;

import com.app.utils.base.j2se.Convert;
import com.app.utils.base.j2se.StringHandler;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class GoodsDetail extends GoodsBase{
    public String desc_str;
    public List<String> banner;
    public List<String> desc_pic;
    //规格
    public List<Map<String,Object>> units;

    public static GoodsDetail convert(Map<String, Object> data){
        GoodsDetail goodsDetail = new GoodsDetail();
        goodsDetail.id= Convert.objToStr(data.get("item_spu_id"));
        goodsDetail.name= Convert.objToStr(data.get("item_name"));
        goodsDetail.desc_str=Convert.objToStr(data.get("describe"));
        goodsDetail.banner=(ArrayList<String>)data.get("main_image_list");
        goodsDetail.desc_pic=(ArrayList<String>)data.get("item_detail_images");
        goodsDetail.units =((ArrayList<Map<String,Object>>)data.get("item_sku_list")).stream().peek(x->{
            long price1 = StringHandler.yuanToFen(Convert.objToStr(x.get("supply_price")));
            x.remove("short_name");
            x.remove("supply_price");
            x.remove("cost_price");
            x.remove("sku_type");
            if(Convert.objToInt(x.get("weight"))==0){
                x.remove("weight");
            }

            long price2 = StringHandler.yuanToFen(Convert.objToStr(x.get("sale_price")));
            if(price2-price1<500){
                price2 += price2-price1+500;
            }
            x.put("sale_price", StringHandler.getFloat(StringHandler.fenToYuan(Convert.objToStr(price2)),0.00F));
        }).collect(Collectors.toList());
        return goodsDetail;
    }
}
